<%--
  Created by IntelliJ IDEA.
  User: LQ
  Date: 2023/9/8
  Time: 14:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <jsp:include page="../Header.jsp"/>
    <title>字典管理</title>
</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Style -->
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="btn-group " style="width: 100%" id="toolbar">
                <div class="col-sm-6">
                    <div class="form-group form-search">
                        <label class="col-sm-3 control-label">字典名称：</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="querySeachName" name="querySeachName"
                                   placeholder="请输入字典名称">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <button type="button" class="btn btn-info" id="bt-serach" onclick="tree.queryTreeData('dics')">
                        <i class="fa fa-search"></i>&nbsp;查询
                    </button>
                    <button type="button" class="btn btn-success" onclick="com.clearFormItem(),com.setRootName()"
                            data-toggle="modal" data-target="#modal-form" name="add">
                        <i class="fa fa-plus"></i>&nbsp;新增
                    </button>
                    <button type="button" class="btn btn-danger" id="bt-del" disabled
                            onclick="com.deleteAllMessage('dics')" name="delete">
                        <i class="fa fa-trash"></i>&nbsp;批量删除
                    </button>
                    <button type="button" class="btn btn-danger"  onclick="com.clearSearch()">
                        <i class="fa fa-refresh"></i>&nbsp;重置
                    </button>
                </div>
            </div>
            <table id="table-tree"></table>
        </div>
    </div>
    <!-- End Panel Style -->
</div>

<div class="modal inmodal" data-backdrop="static" id="modal-form" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight">
            <div class="modal-body">
                <div class="row">
                    <h3>字典信息</h3>
                    <form class="form-horizontal m-t" id="myForm">
                        <input type="hidden" id="parentcode" name="parentcode" value="">
                        <input type="hidden" id="dicid" name="dicid" value="">
                        <input type="hidden" id="diccode" name="diccode" value="">
                        <input type="hidden" id="sn" name="sn" value="">
                        <input type="hidden" id="dicsJson" name="dicsJson" value="">

                        <div class="form-group">
                            <label class="col-sm-3 control-label">父级字典：</label>
                            <div class="col-sm-8">
                                <div class="treeSelect" style="width: 100%;"></div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" l="spot">字典名称：</label>
                            <div class="col-sm-6">
                                <input type="text" id="dicname" name="dicname" class="form-control" required/>
                            </div>
                            <div class="col-sm-2">
                                <button class="btn btn-info btn-circle" type="button" onclick="addDicItem()"><i
                                        class="fa fa-plus"></i>
                                </button>
                            </div>
                        </div>
                        <div class="form-group" id="div-remarks">
                            <label class="col-sm-3 control-label">备注：</label>
                            <div class="col-sm-8">
                                <textarea class="form-control" id="remarks" maxlength="200" name="remarks"
                                          rows="5"></textarea>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" name="bt-close" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="opt.saveDatas(this,'dics')">保存</button>
            </div>
        </div>
    </div>
</div>

<%
    double ranNum = Math.random() * 1000;
%>
<%--树形列表--%>
<script type="text/javascript" src="../script/treeJs.js?v=<%=ranNum%>"></script>
<link rel="stylesheet" type="text/css" media="all" href="../style/ztree/css/zTreeStyle.css"/>
<link rel="stylesheet" type="text/css" media="all" href="../style/ztree/css/treeSelect.css"/>
<script src="../style/ztree/js/jquery.ztree.all.min.js"></script>
<!--treeSelect-->
<script src="../style/ztree/js/treeSelect.js?v=<%=ranNum%>"></script>
<script src="../style/hplus/js/plugins/chosen/chosen.jquery.js"></script>

<script type="text/javascript">
    $(function () {
        //  设置必填提示
        $("#myForm label[l='spot']").prepend("<span style='color: red'>*</span>");
        //  表单验证
        $("#myForm").validate();
        //  树形数据
        tree.loadTreeData('#table-tree', 'dics');
        //  树形下拉选项
        tree.loadTreeSelect(".treeSelect", 'dics');
        //  渲染父级数据
        $('#modal-form').on('shown.bs.modal', function (e) {
            $("div[id^='d-div-']").remove();
            tree.reloadTreeSelectData('dics');
        });
    });

    //  新增多个字典
    function addDicItem() {
        var strHtml = "";
        var index = $(".form-diclist").length + 1;
        strHtml += '<div class="form-group form-diclist" id="d-div-' + index + '" >';
        strHtml += '    <label class="col-sm-3 control-label" l="spot"></label>';
        strHtml += '    <div class="col-sm-6">';
        strHtml += '        <input type="text" id="dicname-' + index + '" name="dicname-' + index + '" class="form-control" required/>';
        strHtml += '    </div>';
        strHtml += '    <div class="col-sm-2">';
        strHtml += '        <button class="btn btn-danger btn-circle" type="button" onclick="delDicItem(' + index + ')">';
        strHtml += '           <i class="fa fa-minus"></i>';
        strHtml += '        </button>';
        strHtml += '    </div>';
        strHtml += '</div>';

        $("#div-remarks").before(strHtml);
    };

    function delDicItem(index) {
        $("#d-div-" + index).remove();
    }
</script>
</body>
</html>

